﻿using H2.NET.Data.Common;
using H2.NET.Web.Pages.SMD.Model;
using H2.NET.Web.Pages.SMD.Service;
using System;

namespace H2.NET.Web.Pages.SMD
{
    public partial class uc_store : TaskControl
    {
        public t_smd_Store store
        {
            get
            {
                return ViewState["store"] == null ? new t_smd_Store() : (t_smd_Store)ViewState["store"];
            }
            set
            {
                ViewState["store"] = value;
            }
        }

        public bool IsShowDeivceList
        {
            get
            {
                return ViewState["IsShowDeivceList"] == null ? true : (bool)ViewState["IsShowDeivceList"];
            }
            set
            {
                ViewState["IsShowDeivceList"] = value;
            }
        }

        public bool IsCanEditAuthID
        {
            get
            {
                return ViewState["IsCanEditAuthID"] == null ? true : (bool)ViewState["IsCanEditAuthID"];
            }
            set
            {
                ViewState["IsCanEditAuthID"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            D_title.Text = "经销商信息";
            if (!IsPostBack)
            {
                store = store ?? new t_smd_Store();
                //search_store.Visible = IsCanEditAuthID;

                l_AuthID.Text = store.AuthID;
                l_storeStatus.Text = store.StoreStatus;
                l_store_type.Text = store.StoreType;
                l_NewFitment.Text = store.NewFitment;
                l_region.Text = store.Region;
                l_province.Text = store.Province;
                l_cityName.Text = store.CityName;
                l_cityClass.Text = store.CityClass;
                l_store_name.Text = store.StoreName;
                l_ContractPerson.Text = store.ContactPerson;
                l_Telephone.Text = store.PhoneNumber;
                l_address.Text = store.StoreAddress;
                l_EapproveSN.Text = store.EapproveSN;

                if (store.DealerID != null)
                {
                    var dealer = DealerService.GetById(store.DealerID.Value);

                    dealer_dealerCode_label.Text = dealer.DealerCode;
                    dealer_name_label.Text = dealer.Name;
                    dealer_region_label.Text = dealer.Region;
                    dealer_province_label.Text = dealer.Province;
                    dealer_cityName_label.Text = dealer.CityName;
                }

                if (IsShowDeivceList)
                {
                    var list = (v_DeviceDeposit._StoreID == store.StoreID).List<v_DeviceDeposit>(Storage.Context3);
                    if (list == null || list.Count == 0)
                    {
                        tr_empty.Visible = true;
                    }
                    rpt_deivce_deposit.DataSource = list;
                    rpt_deivce_deposit.DataBind();

                    device_list.Visible = true;
                }
            }
        }
    }
}